﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Eagle.Web.TagFactory
{
    /// <summary>
    /// 生成input标签
    /// </summary>
    public class Input
    {
        /// <summary>
        /// 生成 type 为 text 的标签
        /// </summary>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        public static string Text(string name, bool createId, string value, string properties)
        {
            return HtmlInput("text", name, createId, value, properties);
        }

        /// <summary>
        /// 生成 type 为 password 的标签
        /// </summary>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        public static string Password(string name, bool createId, string value, string properties)
        {
            return HtmlInput("password", name, createId, value, properties);
        }

        /// <summary>
        /// 生成 type 为 hidden 的标签
        /// </summary>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        public static string Hidden(string name, bool createId, string value, string properties)
        {
            return HtmlInput("hidden", name, createId, value, properties);
        }

        /// <summary>
        /// 生成 type 为 checkbox 的标签
        /// </summary>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        public static string CheckBox(string name, bool createId, string value, string properties)
        {
            return HtmlInput("checkbox", name, createId, value, properties);
        }

        /// <summary>
        /// 生成 type 为 radio 的标签
        /// </summary>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        public static string Radio(string name, bool createId, string value, string properties)
        {
            return HtmlInput("radio", name, createId, value, properties);
        }

        /// <summary>
        /// 生成Html标签
        /// </summary>
        /// <param name="inputType">标签类型</param>
        /// <param name="name">标签名字</param>
        /// <param name="createId">是否生成标签的Id</param>
        /// <param name="value">标签值</param>
        /// <param name="properties">标签的其他属性</param>
        /// <returns></returns>
        private static string HtmlInput(string inputType, string name, bool createId, string value, string properties)
        {
            string htmlTag = string.Empty;
            if (createId)
            {
                htmlTag = "<input type=\"" + inputType + "\" name=\"" + name + "\" id=\"" + name + "\" value=\"" + value + "\" " + properties + " />";
            }
            else
            {
                htmlTag = "<input type=\"" + inputType + "\" name=\"" + name + "\" value=\"" + value + "\" " + properties + " />";
            }
            return htmlTag;
        }
    }
}
